<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
</head>
<body>
<div class="layui-tab page-content-wrap">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form"  style="width: 90%;padding-top: 20px;">
                {% csrf_token %}
                <div class="layui-form-item">
                    <label class="layui-form-label">当前机构：</label>
                    <div class="layui-input-block">
                        <select id="text1" lay-verify="Pname" class="layui-input">
                            {% for m,k in menu.items %}
                            <option value={{ m }}>{{ k }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="adminInfo" style="margin-top: 30px;width: 45%">保存</button>
                        <button id="cancel" type="button" class="layui-btn" style="margin-top: 30px;width: 45%;float:right">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/js/jquery.cookie.js" ></script>
<script src="/static/layui/common.js" ></script>
<script>
    layui.use(['form','element','layer'], function() {
        var form = layui.form();
        re_url = "{{url_data|safe}}";
        form.verify({
            Pname: function(value){
                if(value.length < 1){
                    return '请选择上级菜单节点！';
                }
            }
        });
        form.on('submit(adminInfo)', function(data){
            var P_id=$("#text1 option:selected").val();
            var index = layer.load(2, {shade: [0.2, '#5B5B5B']});
            $.ajax({
                url: 'change_org.html',
                type: 'POST',
                data:{'key': P_id,'type':re_url},
                headers:{'X-CSRFtoken':$.cookie('csrftoken')},
                success: function (base) {
                    if (base == 'true'){
                        layer.msg('资料修改成功！', {icon: 1});
                        //下面为跳出iframe框架的页面跳转
                        setTimeout("window.parent.location.reload();", 2000 )
                    }else {
                        layer.close(index);
                        layer.msg('编辑资料失败，请联系系统管理员！', {icon: 2});
                    }
                }
            })
            return false;
        });
        $("#cancel").click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);//关闭当前页
        })
    })
</script>